﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class IWeapon
{
	//属性
	protected int m_AtkPlusValue = 0;
	protected int m_Atk = 0;
	protected float m_Range = 0;

	protected GameObject m_GameObject = null;
	protected ICharacter m_WeaponOwner = null;//武器拥有者

	//发射特效
	protected float m_EffectDisplayTime = 0;
	protected ParticleSystem m_Particles;
	protected AudioSource m_Audio;
	
	//显示子弹特效
	protected void ShowBulletEffect(Vector3 targetPosition, float disPlayTime)
	{
		m_EffectDisplayTime = disPlayTime;
	}

	//显示枪口特效
	protected void ShowShootEffect()
	{
		if(m_Particles != null)
		{
			m_Particles.Stop();
			m_Particles.Play();
		}
	}

	//显示音效
	protected void ShowSoundEffect(string clipName)
	{
		if (m_Audio == null)
			return;
		IAssetFactory factory = Factory.GetAssetFactory();
		var clip = factory.LoadAudioClip(clipName);
		if (clip == null)
			return;
		m_Audio.clip = clip;
		m_Audio.Play();
	}

	//攻击目标
	public abstract void Fire(ICharacter target);
}

public class WeaponGun:IWeapon
{
	public WeaponGun()
	{

	}

	public override void Fire(ICharacter target)
	{
		ShowShootEffect();
		ShowBulletEffect(target.GetPosition(), 0.3f, 0.2f);
		ShowSoundEffect("GunShot");

		target.UnderAttack(m_WeaponOwner);
	}
}

public abstract class ICharacter
{
	private IWeapon m_Weapon = null;

	public void SetWeapon(IWeapon Weapon)
	{
		m_Weapon = Weapon;
	}
}